import requests
import time
import json
import re

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36',
    'referer': 'https://www.weather.com.cn/'
}
url = f'https://d1.weather.com.cn/calendar_new/2025/101180101_202511.html'
response = requests.get(url, headers=headers, params={'_': int(time.time() * 1000)})

response_text = response.content.decode('utf-8')
result = re.search(r'var fc40 = \[(.*?)]', response_text)
results = result.group(1).split("},{")
results[0] = results[0][1:]
results[-1] = results[-1][:-1]
for result in results:
    date = re.search(r'"date":"(.*?)"', result).group(1)
    max_t_obs = re.search(r'"maxobs":"(.*?)"', result).group(1)
    max_t = re.search(r'"max":"(.*?)"', result).group(1)
    min_t_obs = re.search(r'"minobs":"(.*?)"', result).group(1)
    min_t = re.search(r'"min":"(.*?)"', result).group(1)
    nl = re.search(r'"nl":"(.*?)"', result).group(1)
    nlyf = re.search(r'"nlyf":"(.*?)"', result).group(1)
    str_date = date[:4] + '年' + date[4:6] + '月' + date[6:] + '日'
    print(
        f'日期:{str_date} 农历:{nlyf + nl} 最高温度:{max_t if max_t else max_t_obs}℃, 最低温度:{min_t if min_t else min_t_obs}℃')
